<!-- 首页其他内容组件 -->
<template>
  <div class="other" infinite-scroll-distance="10" v-infinite-scroll="loadMore">
    <div class="bg" v-if="hideBg"></div>
    <div class="categorys">
      <div class="category-secondary">
        <div
          class="item"
          v-for="categorydata in categoryDatas.category"
          :key="categorydata.cat_id"
        >
          <div class="box">
            <img :src="categorydata.touch_icon" class="img" />
          </div>
          <div class="name" v-text="categorydata.cat_name"></div>
        </div>
      </div>
      <div class="category-brand">
        <div class="title">品牌精选</div>
        <ul class="list">
          <li
            class="item"
            v-for="brand in categoryDatas.brand"
            :key="brand.brand_id"
          >
            <div class="box">
              <img :src="brand.brand_logo" class="img" />
            </div>
            <div class="name" v-text="brand.brand_name"></div>
          </li>
        </ul>
      </div>
      <List :moreData="categorylists" :loading="loading"></List>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import List from "@/components/List";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    List,
  },
  data() {
    //这里存放数据
    return {
      hideBg: true,
      page: 1,
      size: 10,
      cat_id: "",
      categoryDatas: [],
    };
  },
  //监听属性 类似于data概念
  computed: {
    categoryData() {
      return this.$store.state.categoryData;
    },
    categorylists() {
      return this.$store.state.categorylist;
    },
    loading() {
      return this.$store.state.loading;
    },
  },
  //监控data中的数据变化
  watch: {
    categoryData() {
      this.categoryDatas = this.$store.state.categoryData;
      console.log(this.categoryDatas);
    },
    $route(to) {
      this.$store.state.categorylist = [];
      document.documentElement.scrollTop = 0;
      this.cat_id = to.query.cat_id;
      this.page = 1;
    },
  },
  //方法集合
  methods: {
    loadMore() {
      this.page = this.page + 1;
      this.$store.dispatch("Actchangecategorylist", {
        cat_id: this.cat_id,
        page: this.page,
        size: this.size,
      });
    },
  },
  mounted() {},
  created() {
    this.cat_id = this.$route.query.cat_id;
    console.log(this.cat_id);
    this.$store.dispatch("ActchangecategoryData", { cat_id: this.cat_id });
    this.$store.dispatch("Actchangecategorylist", {
      cat_id: this.cat_id,
      page: this.page,
      size: this.size,
    });
  },
};
</script>
<style lang="less">
em {
  font-style: normal;
}
.other {
  min-height: 100rem;
  .bg {
    height: 8.1rem;
    background-color: #f34646;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1;
  }
  .categorys {
    .item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      text-align: center;
      margin-bottom: 1rem;
      .box {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        height: 7.5rem;
        img {
          width: 80%;
          height: auto;
          display: block;
        }
      }
      .name {
        font-size: 1.2rem;
      }
    }
    .category-secondary {
      background-color: #fff;
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      border-radius: 1rem;
      padding: 1rem;
      margin: 0 1rem 1rem;
      .item {
        width: 20%;
      }
    }
    .category-brand {
      background-color: #fff;
      border-radius: 1rem;
      margin: 0 1rem;
      .title {
        font-size: 1.5rem;
        color: #000;
        padding: 2rem 2rem 1rem;
      }
      .list {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        .item {
          width: 25%;
        }
      }
    }
    .product-list {
      padding: 0.4rem 0.4rem 0;
      .prolist {
        display: flex;
        flex-wrap: wrap;
        padding: 0 0.6rem;
        position: relative;
        overflow: hidden;
        margin-bottom: 1rem;
        .prolist-item {
          position: relative;
          overflow: hidden;
          float: left;
          width: 49%;
          padding: 0.6rem 0 0;
          border-radius: 0.5rem;
          margin-top: 0;
          &:nth-child(2n-1) {
            padding-right: 0.6rem;
          }
          .pro-img {
            height: auto;
            width: 100%;
            float: none;
            border: 0;
            background-color: #fff;
            border-radius: 0.5rem 0.5rem 0 0;
            overflow: hidden;
            .img-box {
              position: relative;
              display: block;
              padding-top: 100%;
              img {
                display: block;
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
              }
            }
          }
          .pro-info {
            position: relative;
            margin-left: 0;
            padding: 0.8rem;
            background-color: #fff;
            border-radius: 0 0 0.5rem 0.5rem;
            h4 {
              font-size: 1.4rem;
              height: 3.8rem;
              line-height: 1.9rem;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
            .currency-price {
              padding: 6px 0px 8px;
              .currency-price-warp {
                font-size: 16px;
                font-weight: 700;
                display: inline-block;
                color: rgb(242, 14, 40);
                em {
                  font-size: 11.2px;
                }
              }
            }
            .outer {
              overflow: hidden;
              height: 2rem;
              display: flex;
              flex-direction: row;
              align-items: center;
              .tag {
                float: left;
                background-color: #f92028;
                color: #fff;
                font-size: 1rem;
                height: 1.6rem;
                line-height: 1.6rem;
                padding: 0 0.5rem;
                border-radius: 0.2rem;
              }
              .label-list {
                .label-img {
                  height: 1.6rem;
                  margin: 0 0 0 5px;
                  float: left;
                  img {
                    height: 100%;
                  }
                }
              }
              span {
                float: left;
                color: #999;
                font-size: 1.2rem;
              }
            }
            .outer_teshu {
              display: inline-block;
              height: 1.6rem;
              margin-bottom: 0.3rem;
              width: 100%;
            }
          }
        }
      }
    }
  }
}
</style>